import * as http from '../apiconfig/index'
import wx from 'weixin-js-sdk'

function getConfig() {
  return http.post('/wx/config', {url: 'www.niceleads.cn'})
    .then(res => {
      return res;
    })
}

const wxApi = {
  wxRegister(callback){
    getConfig()
      .then(res => {
        let data = res.data;
        wx.config({
          debug: false,   //开启调试模式
          appId: data.appId,   //
          timeStamp: data.timeStamp,
          nonceStr: data.nonceStr,
          signature: data.signature,
          jsApiList: [
            'onMenuShareTimeline',
            'onMenuShareAppMessage',
            'onMenuShareQQ',
            'onMenuShareWeibo',
            'onMenuShareQZone',
            'chooseWXPay'
          ]
        })
      })
      .catch(error => {
        console.log(error);
      });

    wx.ready(res => {
      if(callback){
        callback();
      }
    })
  }































};

export default wxApi;
